package com.hl.controller;

import com.hl.domain.Gongshi;
import com.hl.service.GongShiService;
import com.hl.service.impl.GongShiServiceImpl;
import com.hl.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/gongshi")
public class GongShiController {
    @Autowired
    private GongShiServiceImpl gongShiServiceimpl;

    @GetMapping("/findall")
    public R findall(){
        return R.success(gongShiServiceimpl.findall());
    }

    @PutMapping("/update")
    public R update(Gongshi gongshi){
        int i = 0;
        i = gongShiServiceimpl.update(gongshi);
        if (i == 1){
            System.out.println("修改成功！");
            return R.success(i);
        }else {
            System.out.println("修改失败");
            return R.fail(i);
        }
    }

    @PostMapping("/add")
    public R insert(Gongshi gongshi){
        int i = 0;
        i = gongShiServiceimpl.add(gongshi);
        if (i == 1){
            System.out.println("新增成功！");
            return R.success(i);
        }else {
            System.out.println("新增失败");
            return R.fail(i);
        }
    }

    @DeleteMapping("/del")
    public R del(int id){
        int i = 0;
        i = gongShiServiceimpl.del(id);
        if (i == 1){
            System.out.println("删除成功！");
            return R.success(i);
        }else {
            System.out.println("删除失败");
            return R.fail(i);
        }
    }

    @GetMapping("/findLike")
    public R findLike(String name){
        return R.success(gongShiServiceimpl.findLike(name));
    }

}
